#include <iostream>
#include <unordered_map>

using namespace std;

unordered_map<string, int> mp;

const int N = 110;
int a[N];
string path;
int n = 100;

int t[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool check2(int x, int y)
{
	return y >= 1 && y <= t[x];
}

bool check(string s)
{
	int year = 0;
	for(int i = 0; i < 4; i++)
	{
		year = year * 10 + s[i] - '0';
	}
	int month = 0;
	for(int i = 4; i < 6; i++)
	{
		month = month * 10 + s[i] - '0';
	}
	int day = 0;
	for(int i = 6; i < 8; i++)
	{
		day = day * 10 + s[i] - '0';
	}
	if(year == 2023 && month >= 1 && month <= 12)
	{
		return check2(month, day);
	}
	return false;
}

void dfs(int pos)
{
	if(pos > 8)
	{
		if(check(path)) 
		{
			mp[path]++;
		}
		return;
	}
	for(int i = pos; i <= n; i++)
	{
		path.push_back(a[i] + '0');
		dfs(pos + 1);
		path.pop_back();
	}
}

int main()
{
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	dfs(1);
	
	cout << mp.size() << endl;
	
	return 0;
}
